import 'dart:core';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:unt/About.dart';
import 'package:unt/Intentpage.dart';
import 'package:unt/RowDemo.dart';


void main() {
  runApp(
    MaterialApp(home: TextHomePage()),
  );
}

class TextHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TextHomePageState();
  }
}

class TextHomePageState extends State<TextHomePage>  with SingleTickerProviderStateMixin{
  late AnimationController _animationController;
  double size = 100;
  late Animation<double>  animation;
  late Animation  sizeanimation;
  @override
  void initState() {
    super.initState();
    // 第一步创建 AnimationController
    setState(() {
      _animationController = AnimationController(
        vsync: this,
        duration:Duration(seconds: 2),
      );
    });
    // 第二步设置curve值
    animation = CurvedAnimation(parent: _animationController,curve:Curves.linear);
    sizeanimation = Tween(begin: 50.0,end: 150.0).animate(animation);
    _animationController.addListener(() {
      setState(() {
        size = sizeanimation.value;
      });
    });
    _animationController.addStatusListener((status) {
      if(status == AnimationStatus.completed){
        _animationController.reverse();
      }else if(status == AnimationStatus.dismissed){
        _animationController.forward();
      }
    });
  }
  /**
   * 1。Animation: 抽象类
   *  *监听动画状态的改变
   *  *value
   *  *status
   *  2。AnimationController继承Animation
   *  *vsync 同步信号
   *  *forward（）： 向前执行动画
   *  *reverse（）： 反转执行动画
   *  3。CurvedAnimation：
   *   *作用 设置动画执行的速率（速度曲线）
   *   4。Tween：设置动画执行的value范围
   *    *begin： 开始值
   *    *end： 结束值
   */
  @override
  Widget build(BuildContext context) {
    // AnimationController(vsync: this);
    return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Text("listview"),
          ),
          body:  Center(
              child: AnimatedBuilder(
                //动画的控制器
                animation: _animationController,
                //这个函数返回动画的目标widget
                builder: (BuildContext context, Widget? child) {
                  return  Icon(Icons.favorite,color: Colors.red,size: sizeanimation.value);
                },
              )
            // yjhAnimatedIcon(sizeanimation)
            // Icon(Icons.favorite,color: Colors.red,size: size,)
          ),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.error),
            onPressed: (){
              // _animationController.forward();
              if(_animationController.isAnimating){
                _animationController.stop();
              }else {
                _animationController.forward();
              }
            },
          ),
        )
    );
  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _animationController.dispose();
  }
}
class yjhAnimatedIcon extends AnimatedWidget{
  final Animation  sizeanimation;
  yjhAnimatedIcon(this.sizeanimation) : super(listenable: sizeanimation);
  @override
  Widget build(BuildContext context) {
    return Icon(Icons.favorite,color: Colors.red,size: sizeanimation.value);
  }
}

